package com.mgface.jersey.core;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class DBUtilsTemplate {

	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public <T> T get(String sql, ResultSetHandler<T> rsh, Object... params) throws SQLException {
		QueryRunner runner = new QueryRunner(jdbcTemplate.getDataSource());
		return runner.query(sql, rsh, params);
	}
}
